package com.zhang.infrastructure.util.base;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * description
 *
 * @author zhangFanJun
 * @date 2024-03-08 13:59
 **/
public class ContextUtil {

    /**
     * 从上下文获取请求
     * */
    public static HttpServletRequest getRequest(){

        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if(Objects.isNull(attributes)){
            return null;
        }
        return attributes.getRequest();
    }
}
